#include <exception>
#include "Device.h"
#include "CDSlotClose.h"

CDSlotClose::CDSlotClose(Stereo * dev) {
	if (dev == 0) { throw std::exception("null pointer in CDSlotClose()..."); }
	mDevice = dev;
	mLastState = dev->getOnOffState();
	mLastCDState = dev->getCDState();
}

void CDSlotClose::Execute() {
	mLastState = mDevice->getOnOffState();
	mLastCDState = mDevice->getCDState();
	mDevice->Close();
}

void CDSlotClose::Undo() {
	mDevice->setOnOffState(mLastState);
	mDevice->setCDState(mLastCDState);
}